#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

void copy(int src_fd, int dst_fd)
{
	char buf[512];
	int count;
	while ((count = read(src_fd, buf, 512)))
		write(dst_fd, buf, count);
}

int main(int argc, char *argv[])
{
	int fd;
	int aim = 0;
	if (argc == 1)
		fd=0;
	else if (argv[1][0] == '>') {
		aim = 1;
		fd = open(strtok(argv[1], ">"), O_WRONLY);
	}
	else {
		fd = open(strtok(argv[1], "<"), O_RDONLY);	
	}
	if (aim == 0)
		copy(fd, 1);
	else 
		copy(0, fd);
	close(fd);
	return 0;			
}